#-*-coding:utf-8-*-
from flask_wtf import FlaskForm
# 引入Form元素父类
from wtforms import StringField, PasswordField, DateField, HiddenField, TextAreaField,SubmitField,FileField,SelectField
from wtforms.ext.sqlalchemy.fields import QuerySelectField
# 引入Form验证父类
from wtforms.validators import DataRequired, Length, required

from app.models import *


#后台登录
class AdminLoginForm(FlaskForm):
    #用户名
    username = StringField('username', validators=[DataRequired(message="用户名不能为空"), Length(2, 20, message=u'用户名长度位于2~20之间')],
                           render_kw={'placeholder': '输入用户名', 'Id': 'username', 'lay-verify': "required",
                                      'autocomplete': "off", 'class': "layui-input"})
    #密码
    password = PasswordField('password',
                             validators=[DataRequired(message="密码不能为空"), Length(2, 20, message=u'密码长度位于2~20之间')],
                             render_kw={'placeholder': '输入密码', 'Id': 'password', 'lay-verify': "required",
                                        'autocomplete': "off", 'class': "layui-input"})
    # 提交
    submit = SubmitField(
        label="登入",
        render_kw={
            "class": "layui-btn layui-btn-fluid",'lay-filter':"LAY-user-login-submit",'id':'login-submit','lay-submit':""
        }
    )

# 博文表单
class BlogForm(FlaskForm):
    def query_factory_competence():
        return [r for r in db.session.query(Category).all()]

    # 标题
    title=StringField('标题', validators=[DataRequired(message="标题不能为空")
        , Length(2, 20, message='标题长度位于2~20之间')],
                             render_kw={'placeholder': '请输入文章标题', 'id': 'title', 'lay-verify': "title required",
                                        'autocomplete': "off", 'class': "layui-input"})
    #内容
    content=TextAreaField('内容', validators=[DataRequired(message="内容不能为空")],
                          render_kw={'placeholder': '输入内容', 'id': 'blog_content'})
    #分类
    category = QuerySelectField(label='分类', validators=[required(), DataRequired(message="请选择分类")],
                                  query_factory=query_factory_competence, get_pk=lambda x: x.id,
                                  get_label=lambda x: x.name,render_kw={'lay-search':' ','lay-verify':"required"})
    #图片地址
    imgSrc=HiddenField(label='图片地址',render_kw={'placeholder': '图片地址', 'id': 'imgSrc','class': "layui-input",'disabled':'disabled'})

# 分类表单
class CategoryForm(FlaskForm):
    name=StringField('分类', validators=[DataRequired(message="分类名不能为空"), Length(2, 10, message='长度位于2~10之间')],
                             render_kw={'placeholder': '请输入分类名', 'id': 'name', 'lay-verify': "title required",
                                        'autocomplete': "off", 'class': "layui-input"})

# 回复表单
class ReplyForm(FlaskForm):
    replyContent=TextAreaField('回复内容', validators=[DataRequired(message="回复内容不能为空"), Length(2, 10, message='长度位于2~10之间')],
                             render_kw={'placeholder': '请输入回复内容', 'id': 'replyContent', 'lay-verify': "title required",
                                        'autocomplete': "off", 'class': "layui-textarea"})

# 微语表单
class WhisperForm(FlaskForm):
    Content = TextAreaField('内容', validators=[DataRequired(message="内容不能为空"), Length(2, 255, message='长度位于2~255之间')],
                            render_kw={'placeholder': '请输入内容', 'id': 'Content', 'lay-verify': "title required",
                                       'autocomplete': "off", 'class': "layui-textarea"})

# 回复留言表单
class MessageForm(FlaskForm):
    replyContent=TextAreaField('回复内容', validators=[DataRequired(message="回复内容不能为空"), Length(2, 10, message='长度位于2~10之间')],
                             render_kw={'placeholder': '请输入回复内容', 'id': 'replyContent', 'lay-verify': "title required",
                                        'autocomplete': "off", 'class': "layui-textarea"})

# 相片上传
class PhotoForm(FlaskForm):
    imgName=StringField('图片描述',validators=[DataRequired(message="图片描述不能为空"), Length(2, 10, message='长度位于2~10之间')],
                             render_kw={'placeholder': '请输入图片描述', 'id': 'name', 'lay-verify': "title required",
                                        'autocomplete': "off", 'class': "layui-input"})
    imgSrc=HiddenField(label='图片地址',render_kw={'placeholder': '图片地址', 'id': 'imgSrc','class': "layui-input",'disabled':'disabled'})

# 技能表单
class ToolForm(FlaskForm):
    toolImgSrc=StringField(label='技能图片地址',render_kw={'placeholder': '技能图片地址', 'id': 'toolImgSrc','class': "layui-input",'disabled':'disabled'})
    percent=HiddenField(label='技能百分比',render_kw={'placeholder': '技能百分比', 'id': 'percent', 'class': "layui-input", 'disabled': 'disabled'})

# System字段设置
class SystemForm(FlaskForm):
    key=StringField(label='字段名',render_kw={'placeholder':'请输入字段名','id':'key','class': "layui-input"})
    content=StringField(label='字段描述',render_kw={'placeholder':'请输入字段描述','id':'content','class': "layui-input"})
    type=SelectField(label='字段类型',coerce = int,render_kw={'id':'type'},validators=[DataRequired()],choices=[(1,'文本'),(2,'文件上传'),(3,'文本域'),(4,'链接')],default='1')

class FriendHrefForm(FlaskForm):
    title = StringField(label='友情链接名',render_kw={'placeholder':'请输入友情链接名','id':'title','class': "layui-input"})
    href = StringField(label='链接',render_kw={'placeholder':'请输入链接','id':'href','class': "layui-input"})
    